package com.lianniu.mgr.baseService.staff.controller;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import com.alibaba.fastjson.JSON;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.baseService.staff.model.LogVo;
import com.lianniu.mgr.baseService.staff.service.ILogService;
import com.lianniu.mgr.pagination.PaginationInfo;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/rest")
public class LogRestController {
  private final static Logger logger = Logger.getLogger(LogRestController.class);

  @Resource
  ILogService logService;

  /**
   * 
   * @Title: logList
   * @Description: 添加查询获取日志列表

   * @param request
   * @param logVo
   * @param paginationInfo
   * @return
   * @date: 2016年3月31日 下午4:57:11
   * @return: BaseResult
   */
  @RequestMapping(value = "/logList", method = {RequestMethod.GET})
  public @ResponseBody BaseResult logList(HttpServletRequest request, LogVo logVo,
      PaginationInfo paginationInfo) {
    logger.info("LogRestController logList begin");
    logger.info("LogRestController logList LogVo:" + JSON.toJSONString(logVo));
    Date endTime = logVo.getEndTime();
    if (endTime != null) {
      Calendar calendar = new GregorianCalendar();
      calendar.setTime(endTime);
      calendar.add(Calendar.DATE, 1);// 把日期往后增加一天.整数往后推,负数往前移动
      endTime = calendar.getTime(); // 这个时间就是日期往后推一天的结果
      logVo.setEndTime(endTime);
    }

    try {
      logger.info("logList getLogList start");
      BaseResult baseResult = logService.getLogList(logVo, paginationInfo);
      logger.info("getLogList baseResult:" + JSON.toJSONString(baseResult));
      logger.info("logList getLogList end");
      return baseResult;
    } catch (Exception e) {
      logger.error("LogRestController logList error:" + e.getMessage());
      logger.info("LogRestController logList end");
      return BaseResult.success();
    }


  }
}
